Add Google Cloud Spanner database support#137
Open
fredrikaverpil wants to merge 2 commits intoMaxteabag:mainfrom
Open
Add Google Cloud Spanner database support#137fredrikaverpil wants to merge 2 commits intoMaxteabag:mainfrom
fredrikaverpil wants to merge 2 commits intoMaxteabag:mainfrom
Conversation
Add new database provider for Google Cloud Spanner using the official google-cloud-spanner library's PEP-249 DB-API interface. Features: - Connection via Application Default Credentials or service account JSON - Spanner emulator support for local development - Schema introspection via INFORMATION_SCHEMA - Primary key detection via INDEX_COLUMNS - Index listing and definition retrieval - GoogleSQL dialect with backtick identifier quoting Spanner-specific limitations handled: - Single database per connection (no multi-database support) - No stored procedures, triggers, or sequences - No SSH tunneling (cloud-native service) - INFORMATION_SCHEMA queries require read-only mode (autocommit=True) - gRPC DNS resolver set to native for network compatibility Note: This implementation only supports GoogleSQL dialect. Spanner databases using PostgreSQL dialect are not supported (would require different identifier quoting and potentially different query syntax).
486bfc0 to
235c350
Compare
Spanner databases can use either GoogleSQL or PostgreSQL dialect. This commit adds: - Dialect detection on connect via INFORMATION_SCHEMA.DATABASE_OPTIONS - Dialect stored on connection object (_sqlit_spanner_dialect) - Dialect-aware identifier quoting: - GoogleSQL: `identifier` (backticks) - PostgreSQL: "identifier" (double quotes) - Helper methods for connection-aware quoting Limitations: - quote_identifier() and build_select_query() always use GoogleSQL syntax because they don't have access to the connection object (base class design) - Connection-aware alternatives are provided: - _quote_identifier_for_conn(conn, name) - build_select_query_for_conn(conn, table, limit, ...) Note: PostgreSQL dialect support is experimental and untested. The dialect detection can be verified with GoogleSQL databases to ensure the mechanism works correctly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why (this change)?
Spanner is a fully-managed, scalable, relational database from Google Cloud. Adding support allows sqlit users to connect to and query their Spanner databases!
What (was changed)?
autocommit=Truefor INFORMATION_SCHEMA queries (read-only mode required)GRPC_DNS_RESOLVER=nativeto avoid c-ares DNS issues on some networksDatabaseType.SPANNERto enum and display orderspanneroptional dependency in pyproject.tomlNotes
quote_identifier()andbuild_select_query()default to GoogleSQL syntax due to base class design limitations.